// /***/ "Xp4A":

    // /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return decrypt; });
    // /* unused harmony export decryptAdContent */
    // /* unused harmony export decryptAdKey */
    // /* unused harmony export aesGcmEncrypt */
    // /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return aesGcmDecrypt; });
    // /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return getThirdToken; });
    // /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return createSign; });

    // var _crypto = require("Oygn");
    // var Buffer = require("peL6").Buffer;
    var CryptoJS = require("./crypto-js");
    console.log(14,CryptoJS)
    import createCrypto from './Crypto'
    createCrypto()
    function _requiredPadding(cipher, message) {
        var blockSizeInBytes = cipher._blocksize * 4;
        var reqd = blockSizeInBytes - message.length % blockSizeInBytes;
        return reqd;
    };
    const pkcs7 = {
        pad : function (cipher, message) {
            var reqd = _requiredPadding(cipher, message);
            for (var i = 0; i < reqd; i++) {
                message.push(reqd);
            }
        },
        unpad : function (message) {
            var pad = message.pop();
            for (var i = 1; i < pad; i++) {
                message.pop();
            }
        }
    };

    var C_mode = Crypto.mode = {}
    var Mode = C_mode.Mode = function (padding) {
        if (padding) {
            this._padding = padding;
        }
    };
    
    Mode.prototype = {
        encrypt: function (cipher, m, iv) {
            this._padding.pad(cipher, m);
            this._doEncrypt(cipher, m, iv);
        },
    
        decrypt: function (cipher, m, iv) {
            this._doDecrypt(cipher, m, iv);
            this._padding.unpad(m);
        },
    
        // Default padding
        _padding: pkcs7
    };
    var CBC = C_mode.CBC = function () {
        // Call parent constructor
        Mode.apply(this, arguments);
    };
    
    // Inherit from Mode
    var CBC_prototype = CBC.prototype = new Mode;
    
    // Concrete steps for Mode template
    CBC_prototype._doEncrypt = function (cipher, m, iv) {
        var blockSizeInBytes = cipher._blocksize * 4;
    
        // Encrypt each block
        for (var offset = 0; offset < m.length; offset += blockSizeInBytes) {
            if (offset == 0) {
                // XOR first block using IV
                for (var i = 0; i < blockSizeInBytes; i++)
                m[i] ^= iv[i];
            } else {
                // XOR this block using previous crypted block
                for (var i = 0; i < blockSizeInBytes; i++)
                m[offset + i] ^= m[offset + i - blockSizeInBytes];
            }
            // Encrypt block
            cipher._encryptblock(m, offset);
        }
    };
    CBC_prototype._doDecrypt = function (cipher, c, iv) {
        var blockSizeInBytes = cipher._blocksize * 4;
    
        // At the start, the previously crypted block is the IV
        var prevCryptedBlock = iv;
    
        // Decrypt each block
        for (var offset = 0; offset < c.length; offset += blockSizeInBytes) {
            // Save this crypted block
            var thisCryptedBlock = c.slice(offset, offset + blockSizeInBytes);
            // Decrypt block
            cipher._decryptblock(c, offset);
            // XOR decrypted block using previous crypted block
            for (var i = 0; i < blockSizeInBytes; i++) {
                c[offset + i] ^= prevCryptedBlock[i];
            }
            prevCryptedBlock = thisCryptedBlock;
        }
    };
    
    console.log(103,Crypto)
    
    var gcm = {
        b: '4e894B20a07c80331d1AC8A7e1b6c140',
        s: '34Ba50f5a51Be0192B4a6Dbb0AC51c30',
        as: '5fA05147846fb1528af053B770292C03'
    };
    var decrypt = function decrypt(ciphertext, key) {
        var eb = Crypto.util.base64ToBytes(ciphertext);
        var kb = Crypto.util.base64ToBytes(key);
        var mode = new Crypto.mode.CBC(pkcs7);
        console.log(25,eb,kb,mode)
        var ub = Crypto.AES.decrypt(eb, kb, { asBytes: true, mode: mode });
        var content = Crypto.charenc.UTF8.bytesToString(ub).replace(/\s*\n*\s{2,}/g, '</p><p>');
        content = content.replace(/\n+/g, '</p><p>');
        content = '<p>' + content + '</p>';
        return content;
    };
    
    function inserAdBlock(content) {
        var contents = content.match(/<p>(.*?)<\/p>/g),
            contentsTemp = [],
            textIndex = 0,
            adIndex = 1;
        for (var i = 0; i < contents.length; i++) {
            textIndex += contents[i].match('<p.*?>(.*?)<\/p>')[1].length;
            if (textIndex >= 300 * adIndex) {
                contentsTemp.push(contents[i] + '<div class="chapter-ad-block" data-index=' + adIndex + ' data-ad-exposure="0" id="J_adBlock_' + adIndex + '"></div>');
                adIndex++;
            } else {
                contentsTemp.push(contents[i]);
            }
        }
        return contentsTemp.join('');
    }
    
    function obj2str(args) {
        var keys = Object.keys(args);
        keys = keys.sort(); //参数名ASCII码从小到大排序（字典序）；
        var newArgs = {};
        keys.forEach(function (key) {
            if (args[key] !== "" && args[key] !== 'undefined') {
                //如果参数的值为空不参与签名；
                newArgs[key] = args[key]; //参数名区分大小写；
            }
        });
        var string = '';
        for (var k in newArgs) {
            string += '&' + k + '=' + newArgs[k];
        }
        string = string.substr(1);
        return string;
    }
    var decryptAdContent = function decryptAdContent(ciphertext, key) {
        var mode = new Crypto.mode.CBC(Crypto.pad.pkcs7);
        var eb = Crypto.util.base64ToBytes(ciphertext);
        var kb = Crypto.util.base64ToBytes(key);
        var ub = Crypto.AES.decrypt(eb, kb, { asBytes: true, mode: mode });
        var content = Crypto.charenc.UTF8.bytesToString(ub).replace(/\s*\n*\s{2,}/g, '</p><p>');
        content = content.replace(/\n+/g, '</p><p>');
        content = '<p>' + content + '</p>';
        content = inserAdBlock(content);
        return content;
    };
    
    var decryptAdKey = function decryptAdKey(ciphertext, key) {
        var mode = new Crypto.mode.CBC(Crypto.pad.pkcs7);
        var eb = Crypto.util.base64ToBytes(ciphertext);
        var kb = Crypto.util.base64ToBytes(key);
        var ub = Crypto.AES.decrypt(eb, kb, { asBytes: true, mode: mode });
        return Crypto.charenc.UTF8.bytesToString(ub);
    };
    // var aesGcmEncrypt = function aesGcmEncrypt(plaintext, Secret, Check) {
    //     var iv = _crypto.randomBytes(12);
    //     var cipher = _crypto.createCipheriv('aes-256-gcm', new Buffer(Secret, 'utf8'), iv);
    //     cipher.setAAD(new Buffer(Check));
    
    //     var enc = cipher.update(plaintext, 'utf8');
    //     cipher.final();
    //     return Buffer.concat([iv, enc, cipher.getAuthTag()]).toString('hex');
    // };
    
    // aesGcmDecrypt
    var aesGcmDecrypt = function aesGcmDecrypt(plaintext) {
        var Secret = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '' + gcm.as;
        var Check = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '' + gcm.b;
        
    
        var text = Buffer.from(plaintext, 'base64');
        var iv = text.slice(0, 12);
        var tag = text.slice(text.length - 16, text.length);
    
        var key = new Buffer(Secret, 'utf8');
        var decipher = _crypto.createDecipheriv('aes-256-gcm', key, iv);
        decipher.setAAD(new Buffer(Check));
        decipher.setAuthTag(tag);
    
        var enc = decipher.update(text.slice(12, text.length - 16));
        enc += decipher.final('utf8');
        console.log(plaintext)
        return enc;
    };
    
    var getThirdToken = function getThirdToken() {
        return gcm.b + ':' + aesGcmEncrypt(JSON.stringify({ time: new Date().getTime() }), gcm.s, gcm.b);
    };
    
    var createSign = function createSign(data) {
        data = Object.assign({}, data, { key: 'bLilf61m' });
        var sign = __WEBPACK_IMPORTED_MODULE_0_md5___default()(obj2str(data));
        data.sign = sign;
        delete data.key;
        return data;
    };
    

    // export default Xp4A
    export {
        decrypt,
        aesGcmDecrypt
    }